documentation
[lhc/web/wiklou.git] / includes / SpecialVersion.php
1 <?php
2 /**#@+
3 * Give information about the version of MediaWiki, PHP, the DB and extensions
4 *
5 * @package MediaWiki
6 * @subpackage SpecialPage
7 *
8 * @bug 2019, 4531
9 *
10 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
11 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
12 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
13 */
14
15 /**
16 * constructor
17 */
18 function wfSpecialVersion() {
19 $version = new SpecialVersion;
20 $version->execute();
21 }
22
23 class SpecialVersion {
24 /**
25 * main()
26 */
27 function execute() {
28 global $wgOut;
29
30 $wgOut->addHTML( '<div dir="ltr">' );
31 $wgOut->addWikiText(
32 $this->MediaWikiCredits() .
33 $this->extensionCredits() .
34 $this->wgHooks()
35 );
36 $wgOut->addHTML( $this->IPInfo() );
37 $wgOut->addHTML( '</div>' );
38 }
39
40 /**#@+
41 * @access private
42 */
43
44 /**
45 * @static
46 */
47 function MediaWikiCredits() {
48 global $wgVersion;
49
50 $dbr =& wfGetDB( DB_SLAVE );
51
52 $ret =
53 "__NOTOC__
54 This wiki is powered by '''[http://www.mediawiki.org/ MediaWiki]''',
55 copyright (C) 2001-2006 Magnus Manske, Brion Vibber, Lee Daniel Crocker,
56 Tim Starling, Erik Möller, Gabriel Wicke, Ævar Arnfjörð Bjarmason,
57 Niklas Laxström and others.
58
59 MediaWiki is free software; you can redistribute it and/or modify
60 it under the terms of the GNU General Public License as published by
61 the Free Software Foundation; either version 2 of the License, or
62 (at your option) any later version.
63
64 MediaWiki is distributed in the hope that it will be useful,
65 but WITHOUT ANY WARRANTY; without even the implied warranty of
66 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 GNU General Public License for more details.
68
69 You should have received [{{SERVER}}{{SCRIPTPATH}}/COPYING a copy of the GNU General Public License]
70 along with this program; if not, write to the Free Software
71 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
72 or [http://www.gnu.org/copyleft/gpl.html read it online]
73
74 * [http://www.mediawiki.org/ MediaWiki]: $wgVersion
75 * [http://www.php.net/ PHP]: " . phpversion() . " (" . php_sapi_name() . ")
76 * " . $dbr->getSoftwareLink() . ": " . $dbr->getServerVersion();
77
78 return str_replace( "\t\t", '', $ret );
79 }
80
81 function extensionCredits() {
82 global $wgExtensionCredits, $wgExtensionFunctions, $wgParser, $wgSkinExtensionFunction;
83
84 if ( ! count( $wgExtensionCredits ) && ! count( $wgExtensionFunctions ) && ! count( $wgSkinExtensionFunction ) )
85 return '';
86
87 $extensionTypes = array(
88 'specialpage' => 'Special pages',
89 'parserhook' => 'Parser hooks',
90 'variable' => 'Variables',
91 'other' => 'Other',
92 );
93 wfRunHooks( 'SpecialVersionExtensionTypes', array( &$this, &$extensionTypes ) );
94
95 $out = "\n* Extensions:\n";
96 foreach ( $extensionTypes as $type => $text ) {
97 if ( count( @$wgExtensionCredits[$type] ) ) {
98 $out .= "** $text:\n";
99
100 usort( $wgExtensionCredits[$type], array( $this, 'compare' ) );
101
102 foreach ( $wgExtensionCredits[$type] as $extension ) {
103 wfSuppressWarnings();
104 $out .= $this->formatCredits(
105 $extension['name'],
106 $extension['version'],
107 $extension['author'],
108 $extension['url'],
109 $extension['description']
110 );
111 wfRestoreWarnings();
112 }
113 }
114 }
115
116 if ( count( $wgExtensionFunctions ) ) {
117 $out .= "** Extension functions:\n";
118 $out .= '***' . $this->listToText( $wgExtensionFunctions ) . "\n";
119 }
120
121 if ( $cnt = count( $tags = $wgParser->getTags() ) ) {
122 for ( $i = 0; $i < $cnt; ++$i )
123 $tags[$i] = "&lt;{$tags[$i]}&gt;";
124 $out .= "** Parser extension tags:\n";
125 $out .= '***' . $this->listToText( $tags ). "\n";
126 }
127
128 if ( count( $wgSkinExtensionFunction ) ) {
129 $out .= "** Skin extension functions:\n";
130 $out .= '***' . $this->listToText( $wgSkinExtensionFunction ) . "\n";
131 }
132
133 return $out;
134 }
135
136 function compare( $a, $b ) {
137 if ( $a['name'] === $b['name'] )
138 return 0;
139 else
140 return LanguageUtf8::lc( $a['name'] ) > LanguageUtf8::lc( $b['name'] ) ? 1 : -1;
141 }
142
143 function formatCredits( $name, $version = null, $author = null, $url = null, $description = null) {
144 $ret = '*** ';
145 if ( isset( $url ) )
146 $ret .= "[$url ";
147 $ret .= "''$name";
148 if ( isset( $version ) )
149 $ret .= " (version $version)";
150 $ret .= "''";
151 if ( isset( $url ) )
152 $ret .= ']';
153 if ( isset( $description ) )
154 $ret .= ', ' . $description;
155 if ( isset( $description ) && isset( $author ) )
156 $ret .= ', ';
157 if ( isset( $author ) )
158 $ret .= ' by ' . $this->listToText( (array)$author );
159
160 return "$ret\n";
161 }
162
163 /**
164 * @return string
165 */
166 function wgHooks() {
167 global $wgHooks;
168
169 if ( count( $wgHooks ) ) {
170 $myWgHooks = $wgHooks;
171 ksort( $myWgHooks );
172
173 $ret = "* Hooks:\n";
174 foreach ($myWgHooks as $hook => $hooks)
175 $ret .= "** $hook: " . $this->listToText( $hooks ) . "\n";
176
177 return $ret;
178 } else
179 return '';
180 }
181
182 /**
183 * @static
184 *
185 * @return string
186 */
187 function IPInfo() {
188 $ip = str_replace( '--', ' - ', htmlspecialchars( wfGetIP() ) );
189 return "<!-- visited from $ip -->\n";
190 }
191
192 /**
193 * @param array $list
194 * @return string
195 */
196 function listToText( $list ) {
197 $cnt = count( $list );
198
199 if ( $cnt == 1 )
200 // Enforce always returning a string
201 return (string)$this->arrayToString( $list[0] );
202 else {
203 $t = array_slice( $list, 0, $cnt - 1 );
204 $one = array_map( array( &$this, 'arrayToString' ), $t );
205 $two = $this->arrayToString( $list[$cnt - 1] );
206
207 return implode( ', ', $one ) . " and $two";
208 }
209 }
210
211 /**
212 * @static
213 *
214 * @param mixed $list Will convert an array to string if given and return
215 * the paramater unaltered otherwise
216 * @return mixed
217 */
218 function arrayToString( $list ) {
219 if ( ! is_array( $list ) )
220 return $list;
221 else {
222 $class = get_class( $list[0] );
223 return "($class, {$list[1]})";
224 }
225 }
226
227 /**#@-*/
228 }
229
230 /**#@-*/
231 ?>